package com.itcm.purchase.controller;


import com.itcm.purchase.common.R;
import com.itcm.purchase.entity.DailyReport;
import com.itcm.purchase.service.DailyReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 每日报表 前端控制器
 * </p>
 *
 * @author cm_fighting
 * @since 2020-07-29
 */
@RestController
@RequestMapping("/purchase/daily-report")
@CrossOrigin
@Api(tags = "每日报表")
public class DailyReportController {

    @Autowired
    private DailyReportService reportService;

    @ApiOperation(value = "保存")
    @PostMapping("save")
    public R save(@RequestBody DailyReport dailyReport) {
        if (reportService.saveReport(dailyReport)) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @ApiOperation(value = "根据日期查询报表")
    @RequestMapping(value = "getByDate", method = {RequestMethod.GET, RequestMethod.POST})
    public R getDailyReportByDate(String date) {
        List<DailyReport> list = reportService.getByDate(date);
        return R.ok().data("list", list);
    }
}

